﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ForestryEnterprise
{
    public partial class BrowseTrees : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                updateData();   
            }
        }

        protected void treeInfo_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow selectedRow = this.treeInfo.SelectedRow;
            this.treeName.Text = selectedRow.Cells[1].Text;
            this.treeAge.Text = selectedRow.Cells[2].Text;
            this.treeHeight.Text = selectedRow.Cells[3].Text;
            this.treeWidth.Text = selectedRow.Cells[4].Text;
            this.seedDesc.Text = selectedRow.Cells[5].Text;
            this.seedColor.Text = selectedRow.Cells[6].Text;
            this.seedWeight.Text = selectedRow.Cells[7].Text;
            this.stemDesc.Text = selectedRow.Cells[8].Text;
            this.stemColor.Text = selectedRow.Cells[9].Text;
            this.stemWidth.Text = selectedRow.Cells[10].Text;
            this.stemHeight.Text = selectedRow.Cells[11].Text;
            this.skinDesc.Text = selectedRow.Cells[12].Text;
            this.skinColor.Text = selectedRow.Cells[13].Text;
            this.skinThickness.Text = selectedRow.Cells[14].Text;
            this.leafDesc.Text = selectedRow.Cells[15].Text;
            this.leafColor.Text = selectedRow.Cells[16].Text;
            this.leafThickness.Text = selectedRow.Cells[17].Text;
            this.leafProportion.Text = selectedRow.Cells[18].Text;
            this.fruitDesc.Text = selectedRow.Cells[19].Text;
            this.fruitColor.Text = selectedRow.Cells[20].Text;
            this.fruitEatable.Checked = selectedRow.Cells[21].Text.ToLower().Equals("true") == true ? true : false;
            this.updateTree.Visible = true;
        }

        private void updateData()
        {
            string statement = "Select Tree.*, Seed.*, Stem.*, Skin.*, Leaf.*, Fruit.* ";
            statement += "From ((((Tree ";
            statement += "left join Seed on Tree.tree_id = Seed.tree_id) ";
            statement += "left join Stem on Tree.tree_id = Stem.tree_id) ";
            statement += "left join Skin on Tree.tree_id = Skin.tree_id) ";
            statement += "left join Leaf on Tree.tree_id = Leaf.tree_id) ";
            statement += "left join Fruit on Tree.tree_id = Fruit.tree_id";
            this.treeInfoData.SelectCommand = statement;
            this.treeInfo.DataBind();
        }

        protected void cancel_Click(object sender, EventArgs e)
        {
            this.updateTree.Visible = false;
        }

        protected void update_Click(object sender, EventArgs e)
        {
            //update tree info


            this.updateTree.Visible = false;
        }
    }
}